<template>
    <div class="app-container">
        <div class="search-box">
            <!-- 搜索表单 -->
            <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" class="search-form-new">
                <el-form-item label="游戏名称" prop="gameId">
                    <el-select style="width: 100%;" filterable clearable v-model="queryParams.gameId"
                        placeholder="请选择游戏名称">
                        <el-option v-for="dict in allGameList" :key="dict.id" :label="dict.name" :value="dict.id" />
                    </el-select>
                </el-form-item>

                <el-form-item label="游戏账号" prop="account">
                    <el-input v-model="queryParams.account" placeholder="请输入游戏账号" clearable />
                </el-form-item>

                <el-form-item label="自编号" prop="selfNumber">
                    <el-input v-model="queryParams.selfNumber" placeholder="请输入自编号" clearable />
                </el-form-item>

                <el-form-item label="关键字" prop="des">
                    <el-input v-model="queryParams.des" placeholder="描述模糊查询" clearable />
                </el-form-item>

                <el-form-item label="是否自营" prop="goodsType">
                    <el-select v-model="queryParams.goodsType" placeholder="请选择" clearable>
                        <el-option label="是" :value="1"></el-option>
                        <el-option label="否" :value="2"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" type="warning" @click="resetQuery">重置</el-button>
                   
                </el-form-item>
            </el-form>
        </div>
        <div class="table_box table_box_new table-section">

            <!-- 表格数据 -->
            <el-table v-loading="loading" :data="accountList" border style="width: 100%">
                <el-table-column prop="account" label="账号" width="150"></el-table-column>
                <el-table-column prop="gameName" label="游戏名称" width="120"></el-table-column>
                <el-table-column prop="groupName" label="区服" width="120"></el-table-column>
                <el-table-column prop="status" label="状态" width="100">
                    <template slot-scope="scope">
                        <el-tag :type="statusMap[scope.row.rentState] ? statusMap[scope.row.rentState].type : ''">
                            {{ statusMap[scope.row.rentState] ? statusMap[scope.row.rentState].name : "" }}</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="price" label="每时价格" width="100"></el-table-column>
                <el-table-column prop="priceDay" label="每日价格" width="100"></el-table-column>
                <el-table-column prop="priceWeek" label="每周价格" width="100"></el-table-column>
                <el-table-column prop="priceSub" label="预付款" width="100"></el-table-column>
                <el-table-column prop="selfNumber" label="自编号" width="100"></el-table-column>
                <el-table-column prop="titleImg" label="主图" width="100">
                    <template slot-scope="scope">
                        <imgBox width="50px" height="50" isWrap="nowrap" :img="scope.row.titleImg"></imgBox>
                    </template>
                </el-table-column>
                <el-table-column prop="goodsType" label="是否自营" width="100">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.goodsType == 1">是</el-tag>
                        <el-tag type="danger" v-if="scope.row.goodsType == 2">否</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="title" label="标题" width="150" >
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="scope.row.title" placement="top-start">
                            <div class="zdy-des">{{ scope.row.title }}</div>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column prop="des" label="描述" width="180">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" :content="scope.row.des" placement="top-start">
                            <div class="zdy-des">{{ scope.row.des }}</div>
                        </el-tooltip>
                    </template>
                </el-table-column>
                <el-table-column prop="createTime" label="发布时间" width="160"></el-table-column>
                <el-table-column prop="createName" label="发布人" width="100"></el-table-column>
                
                <el-table-column prop="remark" label="备注" width="150"></el-table-column>

                <el-table-column label="操作" width="250" fixed="right">
                    <template slot-scope="scope">
                        <el-button v-if="checkPermi(['rentalCheck:handleAudit']) &&scope.row.rentState == 1"  type="add"
                            @click="handleAudit(scope.row)">
                            审核
                        </el-button>
                        <el-button v-if="checkPermi(['rental:edit']) && scope.row.rentState != 3" type="text"
                            @click="handleEdit(scope.row)">
                            编辑
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </div>
        <!-- 审核弹窗 -->
        <el-dialog title="账号审核" :visible.sync="auditDialogVisible" width="500px">
            <el-form ref="auditForm" :model="auditForm" label-width="100px">
                <el-form-item label="审核结果">
                    <el-radio-group v-model="auditForm.rentState">
                        <el-radio :label="2">通过</el-radio>
                        <el-radio :label="5">不通过</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="审核意见" v-if="auditForm.rentState == 5">
                    <el-input type="textarea" :rows="3" placeholder="请输入审核意见" v-model="auditForm.failReason">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="auditDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitAudit">确 定</el-button>
            </div>
        </el-dialog>

        <retalCreate v-if="retalShow" ref="retalCreateRef" @success="handleQuery" @close="retalClose"></retalCreate>
    </div>
</template>

<script>
import { rentalAuditList , rentalCheck  } from "@/api/rental/account";
import retalCreate from "./components/retalCreate.vue";
import Pagination from "@/components/Pagination";
export default {
    components: { Pagination, retalCreate },
    data() {
        return {
            retalShow:false,
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 账号表格数据
            accountList: [],
            // 游戏列表
            gameList: [],
            // 用户列表
            userList: [],

            statusMap: {
                1: {
                    name: "待审核",
                    type: "warning",
                },
                2: {
                    name: "已上架",
                    type: "success",
                },
                3: {
                    name: "出租中",
                    type: "warning",
                },
                4: {
                    name: "已下架",
                    type: "",
                },
                5: {
                    name: "审核不通过",
                    type: "danger",
                },
            },

            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                gameId: '',
                account: '',
                selfNumber: '',
                des: '',
                goodsType: ''
            },
            // 审核表单
            auditForm: {
                id: null,
                rentState: 2,
                failReason: null
            },
            // 下架表单
            offlineForm: {
                id: null,
                failfailReason: null
            },
          
            // 当前选中账号
            currentAccount: {},
            // 弹窗显示控制
            auditDialogVisible: false,
            offlineDialogVisible: false,
            rentDialogVisible: false
        };
    },
    computed: {
        allGameList() {
            return this.$store.getters.allGameList;
        },
    },
    created() {
        this.getList();

    },
    methods: {
        retalClose() {
            this.retalShow = false
        },

        /** 查询账号列表 */
        getList() {
            this.loading = true;
            rentalAuditList(this.queryParams).then(response => {
                this.accountList = response.rows;
                this.total = response.total;
            }).finally(() => {
                this.loading = false;
            });
        },
        /** 查询游戏列表 */
        getGameList() {
            listGame().then(response => {
                this.gameList = response.rows;
            });
        },
        /** 查询用户列表 */
        getUserList() {
            listUser().then(response => {
                this.userList = response.rows;
            });
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.queryParams.pageSize = 10
            this.queryParams.pageNum = 1
            this.handleQuery();
        },
        /** 审核按钮操作 */
        handleAudit(row) {
            this.auditForm.id = row.id;
            this.auditForm.rentState = 2;
            this.auditForm.failReason = "";
            this.auditDialogVisible = true;
        },
        /** 提交审核 */
        submitAudit() {
            const params = {
                id: this.auditForm.id,
                rentState: this.auditForm.rentState,
                failReason: this.auditForm.failReason
            };
            rentalCheck(params).then(response => {
                this.auditDialogVisible = false;
                this.getList();
                this.$message.success("操作成功");
            });
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
             this.retalShow = true
             this.$nextTick(()=> {
                 this.$refs.retalCreateRef.open("edit", row.id);
            })
        },
   
    }
};
</script>

<style scoped>
.search-form {
    margin-bottom: 20px;
}


</style>